interface MessageOptions {
  message: string;
  duration?: number;
}

const Message = {
  success(opts: MessageOptions | string) {
    const messageOptions: MessageOptions =
      typeof opts === "string" ? { message: opts } : opts;
    const { message, duration = 2000 } = messageOptions;

    uni.showToast({
      title: message,
      icon: "none",
      duration: duration,
    });
  },

  fail(opts: MessageOptions | string) {
    const messageOptions: MessageOptions =
      typeof opts === "string" ? { message: opts } : opts;
    const { message, duration = 2000 } = messageOptions;

    uni.showToast({
      title: message,
      icon: "none",
      duration: duration,
    });
  },

  error(opts: MessageOptions | string) {
    const messageOptions: MessageOptions =
      typeof opts === "string" ? { message: opts } : opts;
    const { message, duration = 2000 } = messageOptions;

    uni.showToast({
      title: message,
      icon: "none",
      duration: duration,
    });
  },
};

export default Message;
